//
//  main.m
//  oc_3
//
//  Created by 楼楚 on 15/9/8.
//  Copyright (c) 2015年 Chu Lou. All rights reserved.
//

#import <Foundation/Foundation.h>
@interface Mac : NSObject
{
    int cpu;
    int inch;
}
@end
@implementation Mac
-(void) setCpu:(int)newCpu


{
    cpu = newCpu;
}
-(void) setInch:(int)newInch
{
    inch = newInch;
}
@end


@interface Person : NSObject
{
    //@public
    int age;
    NSString *name;
    Mac *mac;
    
}
- (id)init;
- (void) setAge:(int)newAge;
- (void) setName:(NSString *)newName;

@end
@implementation Person
- (id)init
{
    if(self = [super init])
        
    {
        age = 30;
        name = @"hehehe";
    }
    return self;
}
- (void) setAge:(int)newAge;
{
    age = newAge;
    
}

- (void) setName:(NSString *)newName;
{
    name = newName;
    
}
- (void) setName:(NSString *)newName andAge:(int)newAge
{
    age = newAge;
    name = newName;
}
- (void) setMAC:(Mac *)newMAC
{
    mac = newMAC;
}

@end

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        // insert code here...
        NSLog(@"Hello, World!");
        Person *p = [[Person alloc]init];
        
        //p -> age = 10;// 只能访问public属性 不安全
        [p setAge:20];//封装 效果和上一种方法一样 都是修改属性age
        [p setName:@"hehehe" andAge:10];
        Mac *mac = [[Mac alloc]init];
       [ mac setCpu:64];
        [mac setInch:15];
        [p setMAC:mac];
        //封装，通过定义方法 函数 去操作成员属性或者成员变量 目的：提高代码安全性、可行性、效率
    }
    return 0;
}
